package com.twu.biblioteca;

public class Library {
    private BookList bookList;
    private MovieList movieList;
    private UserList members;
    private String libraryName;


    Library(){
        this.libraryName = "Bibloteca";
        bookList = new BookList();
        movieList = new MovieList();
        members = new UserList();
    }


    public String getName() {
        return libraryName;
    }

    public MovieList getMovieList() { return movieList; }

    public BookList getBookList() {
        return bookList;
    }

    public void checkOut(Object object) throws Exception{
        if(object instanceof BookDetail) {
            ((BookDetail) object).setCheckedOut(true);
            ((BookDetail) object).setCheckedOutBy(members.getCurrentUserId());
        }

        if(object instanceof MovieDetail)
            ((MovieDetail) object).setCheckedOut(true);
            ((MovieDetail) object).setCheckedOutBy(members.getCurrentUserId());

    }

    public void returnCheckedOutItem(Object object) throws Exception{
        if(object instanceof BookDetail)
            ((BookDetail) object).setCheckedOut(false);

        if(object instanceof MovieDetail)
            ((MovieDetail) object).setCheckedOut(false);

    }


    public void login() throws Exception {
        try {
            members.login();
        } catch (Exception e) {
            throw e;
        }
    }

    public UserList getMembers() {
        return members;
    }
}

